//
//  WYCZDiscoverSearchView.swift
//  WYWeibo
//
//  Created by wangyi on 16/7/13.
//  Copyright © 2016年 wangyi. All rights reserved.
//

import UIKit

class WYDiscoverSearchView: UIView, UITextFieldDelegate {

    @IBOutlet weak var textFieldRight: NSLayoutConstraint!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var textField: UITextField!

    //加载 xib
   class func searchView() -> WYDiscoverSearchView {
    
        return UINib(nibName: "WYDiscoverSearchView", bundle: nil).instantiateWithOwner(nil, options: nil).last! as! WYDiscoverSearchView
    }
    
    @IBAction func cancelButton(sender: AnyObject) {
        //取消第一响应者
        textField.resignFirstResponder()
        textFieldRight.constant = 0
        
       UIView.animateWithDuration(0.25) { () -> Void in
        self.layoutIfNeeded()
        }
    
    }
    
    //MARK -- UITextFieldDelegate 代理方法
    func textFieldDidBeginEditing(textField: UITextField) {
        textFieldRight.constant = cancelButton.width
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }

}
